#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<mutex>
#include<thread>
#include<condition_variable>

using namespace std;

int main()
{
	mutex mtx;
	condition_variable cv;
	int n = 100;
	int x = 1;

	thread t1([&, n]() {
		unique_lock<mutex> lock(mtx);
		while (x < n)
		{
			if (x % 2 == 0)
				cv.wait(lock);

			cout << this_thread::get_id() << ": " << x << endl;
			x++;
			cv.notify_one();
		}
		});

	thread t2([&, n]() {
		unique_lock<mutex> lock(mtx);
		cv.wait(lock);
		while (x < n)
		{
			if (x % 2 != 0)
				cv.wait(lock);

			cout << this_thread::get_id() << ": " << x << endl;
			x++;
			cv.notify_one();
		}
		});

	t1.join();
	t2.join();

	return 0;
}